﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MengLin.OOP.DesignPattern.Observer.IPhoneXPriceDown.Models
{
    public class IPhoneX
    {
        /// <summary>
        /// Id
        /// </summary>
        public string IPhoneX_Id { get; set; }

        /// <summary>
        /// 版本
        /// </summary>
        public string IPhoneX_Version { get; set; }

        /// <summary>
        /// 期望的价格
        /// </summary>
        public virtual decimal ExpectIPhoneX_Price { get; set; }
        
        /// <summary>
        /// 价格
        /// </summary>
        public decimal _iPhoneX_Price;
        public decimal IPhoneX_Price
        {
            get
            {
                return _iPhoneX_Price;
            }
            set
            {
                if (value < _iPhoneX_Price)
                {
                    IPhoneXEventArgs iPhoneXEventArgs = new IPhoneXEventArgs
                    {
                        OldPrice = this._iPhoneX_Price,
                        NewPrice = value,
                    };

                    IPhoneXEventHandler?.Invoke(this,iPhoneXEventArgs);
                }
                _iPhoneX_Price = value;
            }
        }

        /// <summary>
        /// 事件
        /// </summary>
        public event EventHandler IPhoneXEventHandler;
    }

    /// <summary>
    /// 事件参数
    /// 一般会为特定的事件去封装个参数类型
    /// </summary>
    public class IPhoneXEventArgs : EventArgs
    {
        public decimal OldPrice { get; set; }
        public decimal NewPrice { get; set; }
        public decimal ExpectPrice { get; set; }
    }
}
